package com.ymatou.iapi.livebuyer.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.livebuyer.parameter.LikeBean;
import com.ymatou.iapi.livebuyer.service.LikeCall;
import com.ymatou.iapi.liveseller.parameter.CreateSellerLiveBean;
import com.ymatou.livevideo.parameter.StreamLiveNotifyBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.sqlwapper.LiveRoomWapper;
import com.ymttest.database.sqlwapper.YmtLoggingWapper;
import com.ymttest.utils.TestDataManager;
/**
*比心
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Like{
	private static LikeBean likeBean;
	private static LikeCall likeCall;
	private static Integer liveid;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("比心");
	}

	@Before
	public void caseUp() {
		likeBean=new LikeBean();
		likeCall=new LikeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(likeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Like_001() {
		Logger.start(true,"比心成功");
		try {
			LiveRoomCallService.PublishLiveStatCall(null);
			if (liveid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveid = livedto.getId();
			}
			Integer uid=1;
			int count=1;
			int bcount=LiveRoomCallService.getLikeCount(liveid, uid,0);
			likeBean.setLiveId(liveid);
			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("200", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, likeCall.getJsonObject().get("data").getAsJsonObject().get("totalCount").getAsInt()>bcount, "判断totalCount");
			
			Logger.comment("验证日志数据");
			Map m=new YmtLoggingWapper().selectLiveBehaviorById(liveid, uid);
			Logger.debug(m);
			Logger.verifyEquals(3, m.get("BehaviorType"), "验证BehaviorType");
			Logger.verifyEquals(count, m.get("BehaviorValue"), "验证BehaviorValue");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Like_002() {
		Logger.start(true,"不输入liveid失败");
		try {
			if (liveid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveid = livedto.getId();
			}
			Integer uid=1;
			int count=1;
//			likeBean.setLiveId(liveid);
			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("100", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyIsContains("无效的直播编号", likeCall.getString("message"), "验证message");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Like_003() {
		Logger.start(true,"不输入userid失败");
		try {
			if (liveid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveid = livedto.getId();
			}
			Integer uid=1;
			int count=1;
			likeBean.setLiveId(liveid);
//			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("100", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyIsContains("无效的用户编号", likeCall.getString("message"), "验证message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_Like_004() {
		Logger.start(true,"输入错误count");
		try {
			if (liveid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveid = livedto.getId();
			}
			Integer uid=1;
			int count=-1;
			likeBean.setLiveId(liveid);
			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("100", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyIsContains("无效的比心数", likeCall.getString("message"), "验证message");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Like_005() {
		Logger.start(true,"输入多个count");
		try {
			LiveRoomCallService.PublishLiveStatCall(liveid);
			if (liveid == null) {
				CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
				LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
				liveid = livedto.getId();
			}
			Integer uid=1;
			int count=5;
			int bcount=LiveRoomCallService.getLikeCount(liveid, uid,0);
			likeBean.setLiveId(liveid);
			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("200", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, likeCall.getJsonObject().get("data").getAsJsonObject().get("totalCount").getAsInt()>bcount, "判断totalCount");
			
			Logger.comment("验证日志数据");
			Map m=new YmtLoggingWapper().selectLiveBehaviorById(liveid, uid);
			Logger.debug(m);
			Logger.verifyEquals(3, m.get("BehaviorType"), "验证BehaviorType");
			Logger.verifyEquals(count, m.get("BehaviorValue"), "验证BehaviorValue");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Like_006() {
		Logger.start(true,"比心成功,验证LiveRoomStat");
		try {
			LiveRoomCallService.PublishLiveStatCall(null);
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			liveid = livedto.getId();
			LiveRoomCallService.PublishLiveStatCall(liveid);
			Thread.sleep(1000);
			Map liveroom1 = new LiveRoomWapper().selectLiveRoomStatById(liveid);
			Integer uid=1;
			int count=1;
			int bcount=LiveRoomCallService.getLikeCount(liveid, uid,0);
			likeBean.setLiveId(liveid);
			likeBean.setUserId(uid);
			likeBean.setCount(count);
			likeCall.setData(likeBean);
			likeCall.callService();			
			Logger.verifyEquals("200", likeCall.getString("code"), "判断code是否为200");
			Logger.verifyEquals(true, likeCall.getJsonObject().get("data").getAsJsonObject().get("totalCount").getAsInt()>bcount, "判断totalCount");
			LiveRoomCallService.PublishLiveStatCall(liveid);
			Thread.sleep(1000);
			Logger.debug("likec:"+LiveRoomCallService.getLikeCount(liveid, uid,0));
			Map liveroom2 = new LiveRoomWapper().selectLiveRoomStatById(liveid);
			Logger.comment(liveroom1.toString());
			//LikeRealNum 实际点心 LikeNum 虚拟点心
			Logger.comment(liveroom2.toString());
			Logger.verifyEquals(0, liveroom1.get("LikeRealNum"), "验证初始LikeRealNum");
			Logger.verifyEquals(0, liveroom1.get("LikeNum"), "验证初始LikeNum");
			Logger.verifyEquals(1, liveroom2.get("LikeRealNum"), "验证点赞后LikeRealNum");
			Logger.verifyEquals(true, Integer.valueOf(liveroom2.get("LikeNum").toString())>4, "验证点赞后LikeNum");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Like_007() {
		Logger.start(true,"水军比心成功,验证LiveRoomStat");
		try {
			LiveRoomCallService.PublishLiveStatCall(null);
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			initcreatebean.getLiveDto().setGroupId(LiveRoomCallService.CreateGroup("SU"+TestDataManager.getRandomNum(5),initcreatebean.getLiveDto().getUserId()));
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid1 = livedto.getId();
			Integer uid=1;
			LiveRoomCallService.SellerLiveOnline(liveid1, livedto.getUserId());
			StreamLiveNotifyBean notify = LiveRoomCallService.initStreamLiveNotifyBean(liveid1, 1);
			LiveRoomCallService.LiveNotify(notify);
			LiveRoomCallService.enterGroup(liveid1, uid);
			///发送变化-进入直播或者点赞 会触发重新发布
//			LiveRoomCallService.getLikeCount(liveid1, uid, 1);
			LiveRoomCallService.enterGroup(liveid1, 2);
			//调用PublishLiveStat之前
			Map liveroom1 = new LiveRoomWapper().selectLiveRoomStatById(liveid1);
			LiveRoomCallService.PublishLiveStatCall(liveid1);
			//LikeRealNum 实际点心 LikeNum 虚拟点心
			Logger.verifyEquals(0, liveroom1.get("LikeRealNum"), "验证LikeRealNum");
			Logger.verifyEquals(true, Integer.valueOf(liveroom1.get("LikeNum").toString())==0, "验证LikeNum");
			Thread.sleep(1000);
			LiveRoomCallService.PublishLiveStatCall(liveid1);
			Thread.sleep(2000);
			//调用PublishLiveStat之后
			Map liveroom2 = new LiveRoomWapper().selectLiveRoomStatById(liveid1);
			Logger.verifyEquals(0, liveroom2.get("LikeRealNum"), "验证水军LikeRealNum");
			Logger.verifyEquals(true, Integer.valueOf(liveroom2.get("LikeNum").toString())>0, "验证水军LikeNum");
			Logger.verifyNotNull(liveroom2.get("LastRobotLikeTime"), "验证水军LastRobotLikeTime");
			Logger.comment(liveroom1.toString());
			Logger.comment(liveroom2.toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	//手工验证点 - 放置一段时间后查看点赞数不会增加了
	public void Tc_Like_008() {
		Logger.start(true,"超过50w水军不比心");
		try {
			LiveRoomCallService.PublishLiveStatCall(null);
			CreateSellerLiveBean initcreatebean = LiveRoomCallService.initCreatesellerliveBean(null);
			LiveRoom livedto = LiveRoomCallService.CreateSellerLive(initcreatebean);
			int liveid1 = livedto.getId();
			Integer uid=1;
			LiveRoomCallService.SellerLiveOnline(liveid1, livedto.getUserId());
			LiveRoomCallService.enterGroup(liveid1, uid);
			LiveRoomCallService.getLikeCount(liveid1, uid,500000);
			//调用PublishLiveStat之前
			LiveRoomCallService.PublishLiveStatCall(liveid1);
			Map liveroom1 = new LiveRoomWapper().selectLiveRoomStatById(liveid1);
			//LikeRealNum 实际点心 LikeNum 虚拟点心
			Logger.verifyEquals(500000, liveroom1.get("LikeRealNum"), "验证LikeRealNum");
			Thread.sleep(1000);
			LiveRoomCallService.PublishLiveStatCall(liveid1);
			Thread.sleep(1000);
			//调用PublishLiveStat之后
			Map liveroom2 = new LiveRoomWapper().selectLiveRoomStatById(liveid1);
//			Logger.verifyEquals(0, liveroom2.get("LikeRealNum"), "验证水军LikeRealNum");
//			Logger.verifyEquals(true, Integer.valueOf(liveroom2.get("LikeNum").toString())>0, "验证水军LikeNum");
			Logger.verifyNotNull(liveroom2.get("LastRobotLikeTime"), "验证水军LastRobotLikeTime");
			Logger.comment(liveroom1.toString());
			Logger.comment(liveroom2.toString());
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}